We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

how to know the error in $file->moveTo()

Hi all,

I'm trying to upload images to my project Phalcon with Dropzone 4.2.0, but all data captured while trying to $ file-> moveTo () I get an error but not what is.

FileController - uploadAction

    public function uploadAction () {
    //elimina renderizado al ser un ajax
    $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_NO_RENDER);

    //comprueba si hay archivos por subir
    if ($this->request->hasFiles() == true) {
        // Print the real file names and sizes
        foreach ($this->request->getUploadedFiles() as $file) {
            echo $file->getName(), " ", $file->getSize(), "\n";

            $fileObj       = new Files();
            $fileObj->name = $file->getName();
            $fileObj->size = round(($file->getSize()/1024),2);
            $fileObj->type = Files::IMG;
            $fileObj->of   = "Homes";
            $fileObj->ofId = $this->request->getPost('ofId');

            $fileObj->save();

            $file->moveTo('img/' . $file->getName());

            echo "<br>" ;
            echo $file->getError();
        }
    }

}

Notes:

  • $file->getError() give me 1
  • img folder in public is 777

How I can know that errors occur?

Thanks for the help :)



5.6k

Can anyone help me?



58.4k
Accepted
answer

Hey

You try dump at the line code

            $file->moveTo('img/' . $file->getName());
            die();


5.6k

I do not know the causes, but restarting the server manages.

Thanks @Thien